package com.sinochem.sales.service.listener;

import com.sinochem.sales.common.api.vo.SendSmsinfoVO;
import com.sinochem.sales.common.constant.MqQueueConstant;
import com.sinochem.sales.service.service.ISendSmsinfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xuan
 * @date 2018年01月15日13:51:53
 * 监听短信发送请求
 */
@Slf4j
@Component
@RabbitListener(queues = MqQueueConstant.MOBILE_CODE_QUEUE)
public class MobileCodeReceiveListener {
    @Autowired
    private ISendSmsinfoService sendSmsinfoService;

    @RabbitHandler
    public void receive(SendSmsinfoVO sendSmsinfoVO) {
        long startTime = System.currentTimeMillis();
        log.info("消息中心接收到短信发送请求-> 手机号：{} -> 验证码: {} ", sendSmsinfoVO.getMobile(), sendSmsinfoVO.getCode());
        sendSmsinfoService.sendSmsinfo(sendSmsinfoVO);
        long useTime = System.currentTimeMillis() - startTime;
        log.info("短信处理完毕，耗时 {}毫秒", useTime);
    }
}
